package com.iterator.controller.web.goodsManager;

import com.iterator.bean.web.pojo.tcy.Comment;
import com.iterator.bean.web.stone.BaseRespVo;
import com.iterator.bean.web.tcy.CommentListVO;
import com.iterator.service.web.goodsManager.CommentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author tean_cy
 * @date 2021/1/11 12:26
 */
@RestController
@RequestMapping("admin/comment")
public class CommentController {

    @Autowired
    CommentService commentService;

    @RequestMapping("list")
    @RequiresPermissions("admin:comment:list")
    public BaseRespVo list(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit,
                           @Nullable @RequestParam("userId") Integer userId, @Nullable@RequestParam("valueId")Integer valueId,
                           @RequestParam("sort")String sort, @RequestParam("order") String order){
        CommentListVO commentListVO = commentService.list(page,limit,userId,valueId,sort,order);
        if (commentListVO != null){
        return BaseRespVo.ok(commentListVO);
        }
        return BaseRespVo.fail("评论加载失败");
    }

    @RequestMapping("delete")
    @RequiresPermissions("admin:comment:delete")
    public BaseRespVo delete( @RequestBody Comment commentDelete){
        int code = commentService.delete(commentDelete);
        if (code != 0){
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail("评论删除失败");
    }

}
